function $toast(type,mess){
    wx.showToast({
      title:mess,
      icon:type,
      duration:2000
    })
}


function formateTime(date) {
  var date = new Date(date);
  var y = date.getFullYear();
  var m = date.getMonth() + 1;
  m = m < 10 ? ('0' + m) : m;
  var d = date.getDate();
  d = d < 10 ? ('0' + d) : d;
  var h = date.getHours();
  h = h < 10 ? ('0' + h) : h;
  var minute = date.getMinutes();
  var second = date.getSeconds();
  minute = minute < 10 ? ('0' + minute) : minute;
  second = second < 10 ? ('0' + second) : second;
  return y + '/' + m + '/' + d + ' ' + h + ':' + minute ;
}

function getTime(oldTime){    //输出时间
  let oldtime = oldTime
  let showTimeMsg = ''
  let time = new Date().getTime()
  let showTime = time - oldtime
  showTime = Math.floor(showTime/60000)
  // console.log(this.data.showTime);
  if (showTime < 60 ) {
    if (showTime == 0) {
      showTime = 1
    }
    showTimeMsg = '分钟前发布'
  }else if (showTime > 60 && showTime < 1440 ) {
    showTime = Math.floor(showTime/60)
    showTimeMsg = '时前发布'
  }else if (showTime > 1440) {
    showTime = getdetailTime(oldtime)
    showTimeMsg = '发布'
  }

  return {
    time:showTime,
    mgs:showTimeMsg
  }
  }

  function getdetailTime(date) {
    var date = new Date(parseInt(date));
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    // var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    // second = second < 10 ? ('0' + second) : second;
    return y + '-' + m + '-' + d;
  }


module.exports={
  $toast,
  formateTime,
  getTime
}